import json
try:
    from .type_schema import TypeSchema
    from .parsing import parse_abs_type
except ImportError:
    from type_schema import TypeSchema
    from parsing import parse_abs_type
DATA_FILE = "./datatypes.json"
class SystemDataType:
    def __init__(self):
        self.types: dict[str, TypeSchema] = {}
        for _, group in json.load(open(DATA_FILE)).items():
            for each in group:
                if "name" not in each:
                    print(f"no \"name\" for {each}")
                    continue
                if "def" in each:
                    self.types[each["name"]] = parse_abs_type(each["def"])
                elif "short" in each:
                    self.types[each["name"]] = parse_abs_type(each["short"])
                else:
                    print(f"no \"def\" or \"short\" for {each['name']}")

    def explain(self, name: str) -> TypeSchema | None:
        return self.types[name] if name in self.types else None
def test():
    system_data_type = SystemDataType()

if __name__ == "__main__":
    test()